package com.jms;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQTopic;

public class PubSubConsumer {

	public static void main(String[] args) throws JMSException {
		// TODO Auto-generated method stub

		ConnectionFactory cf=new ActiveMQConnectionFactory(
				"failover:tcp://localhost:61616");
		System.out.println(cf);
		Connection conn=cf.createConnection();
		Session session=conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Destination queue=new ActiveMQTopic("heather-topic");
		MessageConsumer consumer=session.createConsumer(queue);
		
		conn.start();
		
		consumer.setMessageListener(new MessageListener() {
			
			public void onMessage(Message msg) {
				// TODO Auto-generated method stub
				TextMessage tm=(TextMessage)msg;
				try {
					System.out.println(tm.getText());
				} catch (JMSException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		System.out.println("msg....");
	}

}
